package com.lgc.demo.collection;

import java.util.HashMap;
import java.util.Stack;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 判断一个字符串中括号是否匹配
 */
public class StackStudy {
    public boolean CheckSymbol(String input) {
        Stack<String> stack = new Stack<>();

        for (int i = 0; i < input.length(); i++) {
            String current = input.substring(i, i + 1);

            if (!current.equals("{") && !current.equals("(") && !current.equals("[") && !current.equals("}") && !current.equals(")") && !current.equals("]")) {
                continue;
            }

            if (current.equals("{") || current.equals("(") || current.equals("[")) {
                stack.push(current);
            } else {
                if (stack.empty()) {
                    return false;
                } else {
                    if ((current.equals("}") && stack.peek().equals("{")) || (current.equals(")") && stack.peek().equals("(")) || (current.equals("]") && stack.peek().equals("["))) {
                        stack.pop();
                    }
                    else {
                        return false;
                    }
                }
            }
        }

        return stack.empty();
    }

    public static void main(String[] arsg) {
        StackStudy stackStudy = new StackStudy();

        boolean isRight = stackStudy.CheckSymbol("s{f[d((dsf)(ds()))]}");
        boolean isRight2 = stackStudy.CheckSymbol("s()");

        ConcurrentHashMap cc = new ConcurrentHashMap();
        cc.size();

        HashMap<String,String> dd=new HashMap<>();
        dd.size();

        int res = 0;
    }
}
